package com.lyf.scm.plan.domain.util;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

/**
 * 需求计划缓存工具类
 *
 * @author wangchlei
 * @date 2020/10/12
 */
public class RequirementsPlanningCacheUtil {
    /**
     * 当前日期（字符串）
     */
    public static String nowDate;
    /**
     * 周维度信息————起始日期
     */
    public static Date weekStartDate;
    public static String weekStartDateStr;
    /**
     * 周维度信息————截止更新日期
     */
    public static Date weekUpEndDate;
    public static Date startDate1;
    public static String startDateStr1;
    public static Date startDate2;
    public static String startDateStr2;
    public static Date startDate3;
    public static String startDateStr3;
    public static Date startDate4;
    public static String startDateStr4;
    public static Date startDate5;
    public static String startDateStr5;
    public static Date startDate6;
    public static String startDateStr6;
    public static Date startDate7;
    public static String startDateStr7;
    public static Date startDate8;
    public static String startDateStr8;
    public static Date startDate9;
    public static String startDateStr9;
    public static Date startDate10;
    public static String startDateStr10;
    public static Date startDate11;
    public static String startDateStr11;
    public static Date startDate12;
    public static String startDateStr12;
    public static Date startDate13;
    public static String startDateStr13;
    public static Date endDate1;
    public static String endDateStr1;
    public static Date endDate2;
    public static String endDateStr2;
    public static Date endDate3;
    public static String endDateStr3;
    public static Date endDate4;
    public static String endDateStr4;
    public static Date endDate5;
    public static String endDateStr5;
    public static Date endDate6;
    public static String endDateStr6;
    public static Date endDate7;
    public static String endDateStr7;
    public static Date endDate8;
    public static String endDateStr8;
    public static Date endDate9;
    public static String endDateStr9;
    public static Date endDate10;
    public static String endDateStr10;
    public static Date endDate11;
    public static String endDateStr11;
    public static Date endDate12;
    public static String endDateStr12;
    public static Date endDate13;
    public static String endDateStr13;

    public static void injectWeekCache(Date date) {
        nowDate = DateUtil.format(date, DatePattern.NORM_DATE_PATTERN);
        weekStartDate = DateUtil.beginOfWeek(date);
        weekUpEndDate = DateUtil.beginOfDay(DateUtil.endOfWeek(DateUtil.offset(weekStartDate, DateField.DAY_OF_WEEK, 11)));
        startDate1 = weekStartDate;
        weekStartDateStr = DateUtil.format(weekStartDate, DatePattern.NORM_DATE_PATTERN);
        startDateStr1 = weekStartDateStr;
        endDate1 = getNextWeekEndDay(startDate1);
        endDateStr1 = DateUtil.format(endDate1, DatePattern.NORM_DATE_PATTERN);
        startDate2 = getNextWeekStartDay(startDate1);
        startDateStr2 = DateUtil.format(startDate2, DatePattern.NORM_DATE_PATTERN);
        endDate2 = getNextWeekEndDay(startDate2);
        endDateStr2 = DateUtil.format(endDate2, DatePattern.NORM_DATE_PATTERN);
        startDate3 = getNextWeekStartDay(startDate2);
        startDateStr3 = DateUtil.format(startDate3, DatePattern.NORM_DATE_PATTERN);
        endDate3 = getNextWeekEndDay(startDate3);
        endDateStr3 = DateUtil.format(endDate3, DatePattern.NORM_DATE_PATTERN);
        startDate4 = getNextWeekStartDay(startDate3);
        startDateStr4 = DateUtil.format(startDate4, DatePattern.NORM_DATE_PATTERN);
        endDate4 = getNextWeekEndDay(startDate4);
        endDateStr4 = DateUtil.format(endDate4, DatePattern.NORM_DATE_PATTERN);
        startDate5 = getNextWeekStartDay(startDate4);
        startDateStr5 = DateUtil.format(startDate5, DatePattern.NORM_DATE_PATTERN);
        endDate5 = getNextWeekEndDay(startDate5);
        endDateStr5 = DateUtil.format(endDate5, DatePattern.NORM_DATE_PATTERN);
        startDate6 = getNextWeekStartDay(startDate5);
        startDateStr6 = DateUtil.format(startDate6, DatePattern.NORM_DATE_PATTERN);
        endDate6 = getNextWeekEndDay(startDate6);
        endDateStr6 = DateUtil.format(endDate6, DatePattern.NORM_DATE_PATTERN);
        startDate7 = getNextWeekStartDay(startDate6);
        startDateStr7 = DateUtil.format(startDate7, DatePattern.NORM_DATE_PATTERN);
        endDate7 = getNextWeekEndDay(startDate7);
        endDateStr7 = DateUtil.format(endDate7, DatePattern.NORM_DATE_PATTERN);
        startDate8 = getNextWeekStartDay(startDate7);
        startDateStr8 = DateUtil.format(startDate8, DatePattern.NORM_DATE_PATTERN);
        endDate8 = getNextWeekEndDay(startDate8);
        endDateStr8 = DateUtil.format(endDate8, DatePattern.NORM_DATE_PATTERN);
        startDate9 = getNextWeekStartDay(startDate8);
        startDateStr9 = DateUtil.format(startDate9, DatePattern.NORM_DATE_PATTERN);
        endDate9 = getNextWeekEndDay(startDate9);
        endDateStr9 = DateUtil.format(endDate9, DatePattern.NORM_DATE_PATTERN);
        startDate10 = getNextWeekStartDay(startDate9);
        startDateStr10 = DateUtil.format(startDate10, DatePattern.NORM_DATE_PATTERN);
        endDate10 = getNextWeekEndDay(startDate10);
        endDateStr10 = DateUtil.format(endDate10, DatePattern.NORM_DATE_PATTERN);
        startDate11 = getNextWeekStartDay(startDate10);
        startDateStr11 = DateUtil.format(startDate11, DatePattern.NORM_DATE_PATTERN);
        endDate11 = getNextWeekEndDay(startDate11);
        endDateStr11 = DateUtil.format(endDate11, DatePattern.NORM_DATE_PATTERN);
        startDate12 = getNextWeekStartDay(startDate11);
        startDateStr12 = DateUtil.format(startDate12, DatePattern.NORM_DATE_PATTERN);
        endDate12 = getNextWeekEndDay(startDate12);
        endDateStr12 = DateUtil.format(endDate12, DatePattern.NORM_DATE_PATTERN);
        startDate13 = getNextWeekStartDay(startDate12);
        startDateStr13 = DateUtil.format(startDate13, DatePattern.NORM_DATE_PATTERN);
        endDate13 = getNextWeekEndDay(startDate13);
        endDateStr13 = DateUtil.format(endDate13, DatePattern.NORM_DATE_PATTERN);
    }

    private static Date getNextWeekEndDay(Date date) {
        return DateUtil.offset(date, DateField.DAY_OF_MONTH, 6);
    }

    private static Date getNextWeekStartDay(Date date) {
        return DateUtil.offset(date, DateField.WEEK_OF_MONTH, 1);
    }
}
